package com.newtouch.bxzs.database.synchronize.mapper;

import com.newtouch.bxzs.database.synchronize.model.SynProductVO;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;

import java.util.Date;
import java.util.List;

/**
 * 产品mapper
 * <p>
 * <b>History:</b>
 * <table border="1">
 * <tr>
 * <th>Date</th>
 * <th>Operator</th>
 * <th>Memo</th>
 * </tr>
 * <tr>
 * <td>2021/2/3 9:23</td>
 * <td>yuanjie</td>
 * <td>Create</td>
 * </tr>
 * </table>
 *
 * @author yuanjie
 * @version 1.0.0
 * @since 1.0.0
 */
@Mapper
public interface ProductMapper {

    /**
     * 批量添加产品数据
     * @param list 产品信息
     * @param createTime 创建时间
     * @return int
     */
    @Insert({"<script>insert into ASSISTANT_PRODUCT(PRODUCT_ID,PRODUCT_CODE,PRODUCT_NAME,PRODUCT_NAME_FULL_SPELLING," +
            "PRODUCT_ABBREVIATION,PRODUCT_TYPE,PRODUCT_GUARANTEE_PERIOD," +
            "PRODUCT_SALE_START_TIME,PRODUCT_SALE_END_TIME,PRODUCT_INITIAL_INSURED_AMOUNT,PRODUCT_INSURE_AGE," +
            "PRODUCT_PAYMENT_METHOD,PRODUCT_INTRODUCTION,IS_MAIN_PRODUCT,DATA_SOURCE," +
            "CREATE_USER_ID,CREATE_TIME) values" +
            "<foreach collection='list' item='item' separator=',' >"+
            "(REPLACE(uuid(),'-','')," +
            "#{item.productCode},#{item.productName},#{item.productNameFullSpelling}," +
            "#{item.productAbbreviation},#{item.productType},#{item.productGuaranteePeriod},#{item.productSaleStartTime}," +
            "#{item.productSaleEndTime},#{item.productInitialInsuredAmount}," +
            "#{item.productInsureAge},#{item.productPaymentMethod},#{item.productIntroduction},0," +
            "#{item.dataSource},admin',#{createTime})" +
            "</foreach>" +
            "ON DUPLICATE KEY UPDATE" +
            " UPDATE_USER_ID = values(CREATE_USER_ID)</script>"})
    int saveProduct(@Param("list") List<SynProductVO>list,@Param("createTime") Date createTime);

    /**
     * 批量添加附加险信息
     * @param list 附加险
     * @param createTime 创建时间
     * @return int
     */
    @Insert({"<script>insert into ASSISTANT_PRODUCT(ADDITIONAL_INSURANCE_ID,ADDITIONAL_INSURANCE_CODE," +
            "ADDITIONAL_INSURANCE_NAME,ADDITIONAL_INSURANCE_NAME_FULL_SPELLING,MAIN_INSURANCE_CODE," +
            "CREATE_USER_ID,CREATE_TIME) values" +
            "<foreach collection='list' item='item' separator=',' >"+
            "(REPLACE(uuid(),'-','')," +
            "#{item.additionalInsuranceCode},#{item.additionalInsuranceName},#{item.additionalInsuranceNameFullSpelling}," +
            "#{item.productCode},admin',#{createTime})" +
            "</foreach>" +
            "ON DUPLICATE KEY UPDATE" +
            " UPDATE_USER_ID = values(CREATE_USER_ID)</script>"})
    int saveAdditional(@Param("list") List<SynProductVO>list,@Param("createTime") Date createTime);
}
